﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RayDen.RayEngine;
using RayDen.RdfViewer.Controllers;

namespace RdfViewer
{
    public partial class MainForm : Form
    {
        public LogController log;
        public SettingsController settings;
        public EngineController engine;

        public MainForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.engine = new EngineController();
            this.log = new LogController(txtLog);
            Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            GlobalConfiguration.Instance.OpenConfig(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Global.Config.xml");
            this.ctlGlobalConfiguration.SelectedObject = GlobalConfiguration.Instance;
            this.ctlEngineConfig.SelectedObject = engine.Config;

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (ctlOpenFrameDialog.ShowDialog() == DialogResult.OK)
            {
                engine.OpenFrame(ctlOpenFrameDialog.FileName);
                lblStatus.Text = "Frame " + ctlOpenFrameDialog.FileName + " opened.";
            }
        }

        private async void btnStartRenderer_Click(object sender, EventArgs e)
        {
            await engine.StartRenderer();
        }

        private void openFrameToolStripMenuItem_Click( object sender, EventArgs e )
        {
            if (ctlOpenFrameDialog.ShowDialog() == DialogResult.OK)
            {
                engine.OpenFrame(ctlOpenFrameDialog.FileName);
                lblStatus.Text = "Frame " + ctlOpenFrameDialog.FileName + " opened.";
            }
        }
    }
}
